package ppms.commons.data.controller;

import java.util.ArrayList;
import ppms.commons.data.entity.IDataEntity;
import ppms.commons.data.event.ITreeEventListener;

public abstract class AbsTreeViewController implements ITreeViewController
{
    private ArrayList<ITreeEventListener> collapseListener      = null;

    private ArrayList<ITreeEventListener> expandListener	= null;

    private ArrayList<ITreeEventListener> selectChangedListener = null;

    private ArrayList<ITreeEventListener> selectedListener      = null;

    public AbsTreeViewController()
    {
	this.collapseListener = new ArrayList<ITreeEventListener>();
	this.expandListener = new ArrayList<ITreeEventListener>();
	this.selectChangedListener = new ArrayList<ITreeEventListener>();
	this.selectedListener = new ArrayList<ITreeEventListener>();
    }
    
    public void onCollapse(IDataEntity dataEntity)
    {
	for(ITreeEventListener listener : this.collapseListener)
	{
	    listener.onCollapse(dataEntity);
	}
    }

    public void onExpand(IDataEntity dataEntity)
    {
	for(ITreeEventListener listener : this.expandListener)
	{
	    listener.onExpand(dataEntity);
	}

    }

    public void onSelectChanged(IDataEntity dataEntity)
    {
	for(ITreeEventListener listener : this.selectChangedListener)
	{
	    listener.onSelectChanged(dataEntity);
	}

    }

    public void onSelected(IDataEntity dataEntity)
    {
	for(ITreeEventListener listener : this.selectedListener)
	{
	    listener.onSelectChanged(dataEntity);
	}
    }

    public void addCollapseListener(ITreeEventListener listener)
    {
	this.collapseListener.add(listener);

    }

    public void addExpandListener(ITreeEventListener listener)
    {
	this.expandListener.add(listener);

    }

    public void addSelectChangedListener(ITreeEventListener listener)
    {
	this.selectChangedListener.add(listener);

    }

    public void addSelectedListener(ITreeEventListener listener)
    {
	this.selectedListener.add(listener);

    }

    public void removeSelectChangedListener(ITreeEventListener listener)
    {
	this.selectChangedListener.remove(listener);

    }

    public void removeSelectedListener(ITreeEventListener listener)
    {
	this.selectedListener.remove(listener);

    }

    public void removeCollapseListener(ITreeEventListener listener)
    {
	this.collapseListener.remove(listener);
    }

    public void removeExpandListener(ITreeEventListener listener)
    {
	this.expandListener.remove(listener);
    }
}
